// +----------------------------------------------------------------------
// | JavaWeb_EleVue_Pro前后端分离旗舰版框架 [ JavaWeb ]
// +----------------------------------------------------------------------
// | 版权所有 2021 上海JavaWeb研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.javaweb.vip/
// +----------------------------------------------------------------------
// | 作者: 鲲鹏 <javaweb520@gmail.com>
// +----------------------------------------------------------------------
// | 免责声明:
// | 本软件框架禁止任何单位和个人用于任何违法、侵害他人合法利益等恶意的行为，禁止用于任何违
// | 反我国法律法规的一切平台研发，任何单位和个人使用本软件框架用于产品研发而产生的任何意外
// | 、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、附带
// | 或衍生的损失等)，本团队不承担任何法律责任。本软件框架只能用于公司和个人内部的法律所允
// | 许的合法合规的软件产品研发，详细声明内容请阅读《框架免责声明》附件；
// +----------------------------------------------------------------------

package com.javaweb.admin.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.javaweb.admin.entity.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.javaweb.admin.query.KdlPurchaseinQuery;
import com.javaweb.admin.query.KdlZ05kdlQuery;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 销售退货入库质检 Mapper 接口
 * </p>
 *
 * @author 鲲鹏
 * @since 2024-01-30
 */
public interface KdlZ05kdlMapper extends BaseMapper<KdlZ05kdl> {

    IPage<KdlZ05kdl> getSaleReturnList(IPage<KdlZ05kdl> page, @Param("req") KdlZ05kdlQuery req);


    @Select("select isnull(convert(varchar(20),dateadd(mi,-5,max(sync_time)),120),'2024-03-28 00:00:00') from kdl_z05kdl_b")
    String GetMaxSyncTime();

    @Select("select t1.*,t2.status from v_kdl_salereturn_inspectionresult t1 left join kdl_inspectionresult_status t2 on t1.cwarehouseid=t2.cwarehouseid and t1.inspectionlot=t2.inspectionlot where pid=#{pid} and isnull(t2.status,'')='' and t1.cwarehouseid<>'1012' and nnum>0 order by t1.inspectionlot")
    List<SaleReturnInspectionResult> getSaleReturnInspectionSendResult(Integer pid);

    @Select("select t1.*,t2.status from v_kdl_salereturn_inspectionresult t1 left join kdl_inspectionresult_status t2 on t1.cwarehouseid=t2.cwarehouseid and t1.inspectionlot=t2.inspectionlot where pid=#{pid} and nnum>0 order by t1.inspectionlot")
    List<SaleReturnInspectionResult> getSaleReturnInspectionResult(Integer pid);

    @Select("select * from kdl_z05kdl_b where pid=${pid}")
    List<KdlZ05kdlB> getGeneralInOutDetail(Integer pid);

    @Select("select distinct pid,vendorso from v_kdl_salereturn_inspectionresult t1 where status='未回写' order by pid")
    List<SaleReturnInspectionResult> getSaleReturnSubmitList();

    //@Select("select TOP 1 * from kdl_z05kdl_b where vendorbatch = '${vendorbatch}' and materialcode=#{materialcode} and boxflag=#{boxflag}")
    @Select("select top 1 z05b.* from kdl_gm gm left join kdl_qff_feedback feedback on gm.principalorderno=feedback.principalorderno  inner join kdl_z05kdl so on feedback.orderno = so.vendorso inner join kdl_z05kdl_b z05b on z05b.pid = so.id and gm.batchno=z05b.sapbatch   where gm.orderno=#{orderno} and z05b.vendorbatch=#{vendorbatch}")
    KdlZ05kdlB getZ05ByMaterialbatch(String orderno,String vendorbatch);

}
